<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <div th:replace="~{common/common-head.html::common-head}"></div>
</head>
<body class="body-common">
<div class="page-container">
    <form class="layui-form layui-form-pane" action="">
        <input type="hidden" name="id" th:value="${file_images.id }" />

                <div class="layui-form-item">
                    <label class="layui-form-label">名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" id="name" maxlength="20" lay-verify="required" autocomplete="off"
                               placeholder="请输入名称" class="layui-input" th:value="${file_images.name}" >
                    </div>
                </div>
                <div class="layui-form-item" >
                    <input type="hidden" id="imageUrl" name="imageUrl">
                    <div class="layui-upload-drag" id="fileUpload">
                        <i class="layui-icon"></i>
                        <p>点击上传，或将文件拖拽到此处</p>
                    </div>
                    <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                        预览图：
                        <div class="layui-upload-list" id="imageWatch">
                            <img  th:src="@{/fileImages/watch(path=${file_images.imageUrl})}">
                        </div>
                    </blockquote>
                </div>


        <div class="layui-form-item" style="text-align: center">
            <span th:if="${session.userAuth==null || #maps.containsKey(session.userAuth,'fileImages/save')}">
            <button class="layui-btn" lay-submit="" lay-filter="save-data">提交</button>
            </span>
            <input type="button" class="layui-btn"  onclick="myback()" value="返回" />
        </div>
    </form>
</div>
<!--
<script src="//res.layui.com/layui/dist/layui.js" charset="utf-8"></script>-->
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(['form', 'layedit', 'laydate','upload'], function () {
        var form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate,upload = layui.upload;
        form.render();

        upload.render({
            elem: '#fileUpload'
            ,url: rootPath+"fileImages/upload"
            ,done: function(res){
                layer.msg('上传成功');
                $("#imageUrl").val(res.data);
                $("#imageWatch").html("<img src='"+rootPath+"fileImages/watch?path="+res.data+"'>")
            }
        });

        //自定义验证规则
        form.verify({});

        //监听提交
        form.on('submit(save-data)', function (data) {
            $.post(rootPath+"fileImages/save",data.field,function (data) {
                if(data.code==0){
                    myAlert("保存成功");
                    setTimeout(function () {
                        myback("fileImages/gotoList");
                    },alertTime)
                }else{
                    myAlert("保存失败->"+data.message)
                }
            });
            return false
        });

    });
</script>

</body>
</html>